<?php

require_once("lib/exception/duplicate_instance_exception.php");
require_once("lib/exception/internal_error_exception.php");

require_once("lib/model/action.php");
require_once("model/article/to/article_to.php");
require_once("model/article/dao/article_dao_factory.php");

class Create_article_action implements Action {

	private $article_to;
	
	public function __construct($article_to) {
		
		$this->article_to = $article_to;
	}
	
	public function do_execute() {
		try {
			$dao = Article_dao_factory::singleton()->get_dao();
			$this->article_to->set_state("wait");
			return $dao->create($this->article_to);
		}
		catch (Duplicate_instance_exception $e) {
			throw new Model_exception($e);
		}
		catch (Internal_error_exception $e) {
			throw $e;
		}
		catch (Exception $e) {
			throw new Exception("Internal error exception --> " . $e);
		}
	}
	
}

?>